import React from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function useAuth({ children }) {
    function Auth() {
        let token = localStorage.getItem('token')
        let WhileList = ['/login', '*']
        let { pathname } = useLocation()
        let Navigate = useNavigate()
        if (!token && !WhileList.includes(pathname)) {
            Navigate('/login')
        }
        return children
    }
    return Auth()
}


export default useAuth
